/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DBKoneksi;

import Login.Login;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.StringTokenizer;
import oracle.jdbc.pool.OracleDataSource;

/**
 *
 * @author Piyo
 */
public class TestConection {

    Connection conn;
    private static Connection connection;
    private boolean ok;
    private String jdbcURL = "jdbc:oracle:thin:@localhost:1521:XE";
//    private String user = "ophin";
//    private String password = "hr";

    public boolean getConnection(Login login) {
        try {

            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL("jdbc:oracle:thin:@localhost:1521:XE");
            conn = ds.getConnection(login.getUsername(), login.getPassword());
//            System.out.println("Koneksi Berhasil");
            ok = true;
        } catch (SQLException ex) {
//            System.out.println("Koneksi Gagal");
            ok = false;
        }
        return ok;
    }

     public static Connection getConnection() {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "ophin", "hr");
            System.out.println("koneksi berhasil");
     } catch (Exception ex) {
            System.out.println("message:Koneksi Gagal  " + ex.getMessage());
        }
        return connection;
    }


    public void setConn(Connection connection) {
        this.connection = connection;
    }
       public static String[] openConfiguration(File file) throws FileNotFoundException, IOException {
        FileInputStream input = new FileInputStream(file);
        String teks = new String();
        int a = 0;
        while ((a = input.read()) != -1) {
            teks += (char) a;
        }
        StringTokenizer tokens = new StringTokenizer(teks,";");
        String result[] = new String[tokens.countTokens()];


        for (int i = 0; i < result.length; i++) {
            result[i] = tokens.nextToken();

        }
        return result;
    }

}
